﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace BTN04.DTO
{
    public class GioHang
    {
        readonly List<CartItem> _item;

        public List<CartItem> Item
        {
            get { return _item; }
        }
        public GioHang()
        {
            _item = new List<CartItem>();
        }

        public void AddItem(CartItem item)
        {
            CartItem hang = new CartItem();
            hang = _item.SingleOrDefault(c=>c.Masp ==item .Masp );
            if (hang != null)
            {
                hang.SoLuong += item.SoLuong;
            }
            else
            {
                _item.Add(item);
            }

        }
        public void UpdateItem(int masp, int soluong)
        {
            CartItem itemUpdate = _item.Single(c => c.Masp == masp);
            itemUpdate.SoLuong = soluong;
        }

        public void RemoveItem(int masp)
        {
            CartItem itemDelete = _item.Single(c=>c.Masp ==masp );
            _item.Remove(itemDelete );
        }

        public int SoLuongHang()
        {
            return _item.Sum(c => c.SoLuong);
        }
    }
}
